#include <iostream>
using namespace std;

int Search_Bin(int A[],int key,int n){
	int low = 0;
	int high = n-1;
	int mid;
	while(low<=high){
		mid=(low+high)/2;
		if(key==A[mid]){
			return mid;
		}
		else if(key<A[mid]){
			high=mid-1;
		}
		else{
			low=mid+1;
		}
	}
	return 0;
} 

void sort(int A[],int n){
	//冒泡法排序
	for(int i=0;i<n-1;i++){
		for(int j=0;j<n-i-1;j++){
			if(A[j]>A[j+1]){
				int t=A[j];
				A[j]=A[j+1];
				A[j+1]=t;
			}
		}
	} 
}

void Print(int A[],int n){
	for(int i=0;i<n;i++){
		cout<<A[i]<<" ";
	}
	cout<<endl;
}
int main()
{
	int A[10]={2,1,4,6,7,3,8,0,5,9};
	Print(A,10);
	sort(A,10);
	Print(A,10);
	cout<<Search_Bin(A,7,10)+1;
	return 0;
}

